-
Notifications
You must be signed in to change notification settings - Fork 3
Separate general policy logic from block builder policy logic to improve usability for other TEE projects #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v2.0.0
Are you sure you want to change the base?
Conversation
|
Technically the refactor looks very good! There are two things that potentially will be raised:
|
|
Below are the methods whose doc blocks changed meaningfully. For each: 1) old, 2) new initialize
/// @notice Initializer to set the FlashtestationRegistry contract which verifies TEE quotes and the initial owner of the contract
/// @notice Initializer to set the FlashtestationRegistry contract which verifies TEE quotes and the initial owner of the contract isAllowedPolicy
/// @notice Check if this TEE-controlled address has registered a valid TEE workload with the registry, and
/// @notice Check if this TEE-controlled address has a valid registry registration and _cachedIsAllowedPolicy
/// @notice isAllowedPolicy but with caching to reduce gas costs
/// @notice Cached variant of workloadIdForTDRegistration
/// @notice Application specific mapping of registration data to a workload identifier Inline: // We expect FPU and SSE xfam bits to be set, and anything else should be handled by explicitly allowing the workloadid
/// @notice Application specific mapping of registration data to a workload identifier Inline: // Uses TDXWorkloadDeriverLib (see the deriver for constants and derivation details). addWorkloadToPolicy
/// @notice Add a workload to a policy (governance only)
/// @notice Add a workload to a policy (governance only). removeWorkloadFromPolicy
/// @notice Remove a workload from a policy (governance only)
/// @notice Remove a workload from a policy (governance only). getWorkloadMetadata
/// @notice Mapping from workloadId to its metadata (commit hash and source locators)
/// @notice Get metadata for an approved workload. |
|
Thank you for the feedback Frieder. I merged in your doc changes. Regarding the other issues this PR addresses, this was a happy accident. Due to the requirement that the storage layout remain unchanged, BasePolicy cannot inherit from OwnableUpgradeable to access the owner state directly. Instead, it uses an abstract hook pattern (_checkPolicyAuthority()) that BlockBuilderPolicy implements by calling _checkOwner(). Similarly, before the tdx policy verification logic was BlockBuilderPolicy, but we decided to make derivers that needed this logic, and I wouldn't want a deriver to inherit from BlockBuilderPolicy so it just made sense to refactor out. @Melvillian do you think you could take a look and let me know what you think? |
Refactor: extract BasePolicy + deriver architecture; keep BlockBuilderPolicy upgrade-safe
Summary
This PR refactors
BlockBuilderPolicyby extracting reusable policy logic into a new abstractBasePolicy, and introduces a pluggable workload-derivation layer (IWorkloadDeriver) so workload ID derivation can evolve without rewriting policy code. The refactor is designed to preserve upgradeability by maintainingBlockBuilderPolicy’s storage layout.Previous Discussion
Discussion occurred in #45 (comment)
What changed
src/BasePolicy.solwith common policy logic (addWorkloadToPolicy,removeWorkloadFromPolicy,getWorkloadMetadata,isAllowedPolicy,_cachedIsAllowedPolicy) and hooks for auth/deriver/cachesrc/interfaces/IPolicyCommon.solfor sharedWorkloadIdtype,WorkloadMetadata, and common events/errorssrc/interfaces/IBasePolicy.solfor the shared policy interfacesrc/interfaces/IWorkloadDeriver.solfor injected workload derivation (workloadIdForQuote(bytes))src/derivers/TDXWorkloadDeriver.solcontaining the current TDX derivation logic behindIWorkloadDeriverBlockBuilderPolicyBlockBuilderPolicynow inheritsBasePolicyand keeps block-builder-specific logic (EIP-712 domain, proof verification, permit nonce handling)workloadDeriverand wired it throughinitialize(...)andsetWorkloadDeriver(...)isAllowedPolicyto derive fromregistration.parsedReportBodyto avoid re-parsing raw quotes on cache misses_setWorkloadDeriverto ensure the configured deriver supports the report-body derivation method assumed by the overrideexamples/DualDeriverPolicy.sol(UNAUDITED EXAMPLE) demonstrating a migration approach that tries an “old” and “new” deriverexamples/TDXTD15WorkloadDeriver.solshowing how a hypothetical future report-body format could be supported by swapping deriverstest/UpgradeRegression.t.solto upgrade a proxy from a legacy policy implementation to the refactoredBlockBuilderPolicyand assert state + behavior preservationtest/Examples.t.sol) and updated existing tests/scripts for the new initializer/deriver wiringWhy
BlockBuilderPolicystorage layout compatibleStorage / upgradeability notes
BasePolicyonly introduces shared storage in the original order (approvedWorkloads,registry) and uses hooks so derived contracts can own additional stateBlockBuilderPolicykeeps its existing slots and introducesworkloadDeriverin reserved space; the upgrade regression test validates this end-to-endTest plan
forge test